<template>
	<view>
		<view
			style="width: 690upx;margin-left: 30upx;margin-top: 30upx;box-shadow: 0 0 10upx #C0C4CC;border-radius: 16upx;padding: 30upx;">
			<u-form :model="form" ref="uForm">
				<u-form-item label="车牌号" label-width="120upx">{{ order['F2'] }}</u-form-item>
				<u-form-item label="驾驶员" labelWidth="120upx">{{ order['F6'] }}</u-form-item>
			</u-form>
		</view>
		<view
			style="width: 690upx;margin-left: 30upx;margin-top: 30upx;box-shadow: 0 0 10upx #C0C4CC;border-radius: 16upx;padding: 30upx;">
			<u-form :model="form" ref="uForm">
				<u-form-item label="扣水">
					<u-input type="number" v-model="form.shui" :placeholder="'请输入口水数值（吨）'" />
				</u-form-item>
				<u-form-item label="扣杂">
					<u-input type="number" v-model="form.za" :placeholder="'请输入口杂数值（吨）'" />
				</u-form-item>
			</u-form>

			<view style="margin-top: 100upx;display: flex;">
				<u-button @click="markUnGood()" type="error">不合格</u-button>
				<u-button @click="submit()" type="primary">提 交</u-button>
			</view>
		</view>

		<u-modal v-model="showAlert" title="系统提示" @confirm="alertConfirm" :show-cancel-button="true">
			<view class="slot-content">
				<view style="text-align: center;padding: 20rpx;">确定标记此车为作废吗</view>
			</view>
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					shui: 0,
					za: 0
				},
				order: '',
				showAlert: false
			};
		},
		methods: {
			alertConfirm(e){
				// 标记作废
				this.$ajax.post({
					url: '/CarWeightLog/markUnGood',
					data: {
						carNum: this.order['F2'],
						shui: this.form.shui,
						za: this.form.za,
						shui_za: Number(this.form.shui) + Number(this.form.za)
					}
				}).then(res=>{
					uni.navigateBack({
						delta:1
					})
				})
			},
			markUnGood() {
				this.showAlert = !this.showAlert
			},
			submit() {
				if (!this.form.shui) {
					this.form.shui = 0;
				}
				if (!this.form.za) {
					this.form.za = 0;
				}
				this.$ajax.post({
					url: '/CarWeightLog/updateRow',
					data: {
						carNum: this.order['F2'],
						shui: this.form.shui,
						za: this.form.za,
						shui_za: Number(this.form.shui) + Number(this.form.za)
					}
				}).then(res => {
					if (res.code == 1) {
						uni.showModal({
							title: "系统提示",
							content: "操作成功",
							success: () => {
								uni.navigateBack({
									delta: 1
								})
							},
							showCancel: false
						})

					}
				});
			}
		},
		onLoad() {
			uni.setNavigationBarTitle({
				title: '扣水扣杂'
			});
			this.order = uni.getStorageSync('car-weight-check') || {};

			console.log(this.order);
		}
	};
</script>

<style lang="scss"></style>
